package com.changgou.order.service.impl;

import com.changgou.order.dao.TaskHisMapper;
import com.changgou.order.dao.TaskMapper;
import com.changgou.order.pojo.Task;
import com.changgou.order.pojo.TaskHis;
import com.changgou.order.service.TaskService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class TaskServiceImpl implements TaskService {

    @Autowired
    private TaskMapper taskMapper;

    @Autowired
    private TaskHisMapper taskHisMapper;

    @Override
    public void delTask(Task task) {
        //设置参数
        task.setDeleteTime(new Date());

        //获取删除条件
        Long id = task.getId();
        task.setId(null);

        //复制数据
        TaskHis taskHis = new TaskHis();
        BeanUtils.copyProperties(task,taskHis);

        //新增历史任务记录
        taskHisMapper.insertSelective(taskHis);

        //删除任务记录
        task.setId(id);
        taskMapper.deleteByPrimaryKey(task);
    }
}
